library(gridExtra)
library(ggplot2)
library(foreign)



# Set working directory. Please set your own
setwd("~/Desktop/PSRM Replication")


data1 <- read.dta("Data/samealltogether15oneoutInt.dta")
data<-data1[data1$id2==1 , ]

data1956<-data[data$id1==1956, ]
data1960<-data[data$id1==1960, ]
data1964<-data[data$id1==1964, ]
data1968<-data[data$id1==1968, ]
data1972<-data[data$id1==1972, ]
data1976<-data[data$id1==1976, ]
data1980<-data[data$id1==1980, ]
data1984<-data[data$id1==1984, ]
data1988<-data[data$id1==1988, ]
data1992<-data[data$id1==1992, ]
data1996<-data[data$id1==1996, ]
data2000<-data[data$id1==2000, ]
data2004<-data[data$id1==2004, ]
data2008<-data[data$id1==2008, ]
data2012<-data[data$id1==2012, ]
data2016<-data[data$id1==2016, ]





theme_base1 <- 
  theme_minimal(base_size=8)  + 
  theme(legend.position=c(0.7, .1),  legend.key.size = unit(1,"line"),
        axis.text=element_text(size=8),axis.title.x=element_text(size=8),axis.title.y=element_text(size=8),
        axis.text.x=element_text(size=5),
        plot.title = element_text(size=8, hjust= 0.5))


d1956<-ggplot(data1956, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 1956") 
d1956


d1960<-ggplot(data1960, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 1960") 
d1960

d1964<-ggplot(data1964, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 1964") 
d1964

d1968<-ggplot(data1968, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 1968") 
d1968

d1972<-ggplot(data1972, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 1972") 
d1972

d1976<-ggplot(data1976, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 1976") 
d1976

d1980<-ggplot(data1980, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 1980") 
d1980


d1984<-ggplot(data1984, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 1984") 
d1984

d1988<-ggplot(data1988, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 1988") 
d1988

d1992<-ggplot(data1992, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 1992") 
d1992

d1996<-ggplot(data1996, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 1996") 
d1996

d2000<-ggplot(data2000, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 2000") 
d2000

d2004<-ggplot(data2004, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 2004") 
d2004

d2008<-ggplot(data2008, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 2008") 
d2008

d2012<-ggplot(data2012, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 2012") 
d2012

d2016<-ggplot(data2016, aes(x=id3, y =estimate)) +   
  geom_point(size = 1) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.4)+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=.9)+
  scale_y_continuous(limits = c(-.2, .25))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.5,15.5))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Without 2016") 
d2016


pdf("Graphs/PresiElectionout2Int.pdf")
grid.arrange(d1956,d1960,d1964,d1968,d1972,d1976,d1980,d1984,
             d1988,d1992,d1996,d2000,d2004,d2008,d2012,d2016,respect=TRUE, ncol=4, nrow=4)
dev.off()    

